
import rpm
#import sys
#def rpm2cpio(fdno, out=sys.stdout, bufsize=2048):
#    """Performs roughly the equivalent of rpm2cpio(8).
#       Reads the package from fdno, and dumps the cpio payload to out,
#       using bufsize as the buffer size."""
#    ts = rpmUtils.transaction.initReadOnlyTransaction()
#    hdr = ts.hdrFromFdno(fdno)
#    del ts
#    
#    compr = hdr[rpm.RPMTAG_PAYLOADCOMPRESSOR] or 'gzip'
#    #XXX FIXME
#    #if compr == 'bzip2':
#        # TODO: someone implement me!
#    #el
#    if compr != 'gzip':
#        raise rpmUtils.RpmUtilsError, \
#              'Unsupported payload compressor: "%s"' % compr
#    f = gzip.GzipFile(None, 'rb', None, os.fdopen(fdno, 'rb', bufsize))
#    while 1:
#        tmp = f.read(bufsize)
#        if tmp == "": break
#        out.write(tmp)
#    f.close()
    

def compareEVR((e1, v1, r1), (e2, v2, r2)):
    # return 1: a is newer than b
    # 0: a and b are the same version
    # -1: b is newer than a
    if e1 is None:
        e1 = '0'
    else:
        e1 = str(e1)
    v1 = str(v1)
    r1 = str(r1)
    if e2 is None:
        e2 = '0'
    else:
        e2 = str(e2)
    v2 = str(v2)
    r2 = str(r2)
    #print '%s, %s, %s vs %s, %s, %s' % (e1, v1, r1, e2, v2, r2)
    rc = rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
    #print '%s, %s, %s vs %s, %s, %s = %s' % (e1, v1, r1, e2, v2, r2, rc)
    return rc
